home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ANMFORMT.ZIP / CGRAPH.ASM < prev    next >
Assembly Source File  |  1991-08-23  |  6KB  |  352 lines

  1. ; my generic graphics routines for C programs
  2.  
  3.  
  4.     .8086
  5.  
  6.     .model    large,c
  7.  
  8. ;*****************************************************************************
  9. ;                 Program code starts here
  10. ;*****************************************************************************
  11.  
  12.  
  13. EQUIP_FLAG    EQU    byte ptr ds:[10h] ; (in Video Display Data Area)
  14.  
  15. CGAbits        EQU    00100000b    ; bits for EQUIP_FLAG
  16. MDAbits        EQU    00110000b
  17.  
  18.  
  19.     .code
  20.  
  21.     public    SetVideoMode
  22. SetVideoMode    proc    far
  23.  
  24.     push    bp        ; preserve caller registers
  25.     mov    bp,sp
  26.     push    ds
  27.  
  28.     mov    ax,40h
  29.     mov    ds,ax        ; DS -> Video Display Data Area
  30.  
  31.     mov    bl,CGAbits    ; BL := bits indicating presence of CGA
  32.     mov    al,6[bp]    ; AL := desired video mode number
  33.  
  34.     mov    ah,al        ; test if desired mode is monochrome
  35.     and    ah,7
  36.     cmp    ah,7
  37.     jne    L01        ; jump if desired mode not 7 or 0Fh
  38.  
  39.     mov    bl,MDAbits    ; BL := bits indicating presence of MDA
  40.  
  41. L01:    and    EQUIP_FLAG,11001111b
  42.     or    EQUIP_FLAG,bl    ; set bits in EQUIP_FLAG
  43.  
  44.     xor    ah,ah        ; AH := 0 (INT 10h function number)
  45.  
  46.     push    bp
  47.     int    10h        ; call ROM BIOS to set the video mode
  48.     pop    bp
  49.  
  50.     pop    ds        ; restore caller registers and return
  51.     pop    bp
  52.  
  53.     ret
  54.  
  55. SetVideoMode endp
  56.  
  57.     public    GetVideoMode
  58. GetVideoMode    proc    far
  59.     
  60.     push    bp
  61.     mov    ah,0Fh        ; Get video mode sub-function
  62.     int    10h        ; call ROM BIOS to get video mode number
  63.     pop    bp
  64.  
  65.     xor    ah,ah        ; AX := video mode number
  66.  
  67.     ret
  68.  
  69. GetVideoMode    endp
  70.  
  71.  
  72. ; LoadPalette(numcolors, startcolor, paletteaddr)
  73.     public    LoadPalette
  74. LoadPalette    proc    far
  75.  
  76.     push    bp
  77.     mov    bp,sp
  78.  
  79.     push    bx
  80.     push    cx
  81.     push    dx
  82.     push    es
  83.     
  84.     mov    bx,8[bp]
  85.     mov    cx,6[bp]
  86.     mov    es,12[bp]
  87.     mov    dx,10[bp]
  88.  
  89.     mov    ax,1012h
  90.     int    10H
  91.  
  92.     pop    es
  93.     pop    dx
  94.     pop    cx
  95.     pop    bx
  96.     pop    bp
  97.  
  98.     ret
  99.  
  100. LoadPalette    endp
  101.  
  102.  
  103. ; initialize the mouse to its default values and display it
  104.     public    InitMouse
  105. InitMouse    proc    far
  106.  
  107.     push    ax
  108.  
  109.     mov    ax,0
  110.     int    33h
  111.     mov    ax,1
  112.     int    33h
  113.  
  114.     pop    ax
  115.  
  116.     ret
  117.  
  118. InitMouse    endp
  119.  
  120. ; display the mouse cursor
  121.     public    ShowMouse
  122. ShowMouse    proc    far
  123.  
  124.     push    ax
  125.  
  126.     mov    ax,1
  127.     int    33h
  128.  
  129.     pop    ax
  130.  
  131.     ret
  132. ShowMouse    endp
  133.  
  134.  
  135. ; hide the mouse cursor
  136.     public    HideMouse
  137. HideMouse    proc    far
  138.     push    ax
  139.  
  140.     mov    ax,2
  141.     int    33h
  142.     
  143.     pop    ax
  144.  
  145.     ret
  146. HideMouse    endp
  147.  
  148. ; read the mouse buttons and cursor position
  149. ; on exit:
  150. ; BX = button state  bit 0 = left button  bit 1 = right button
  151. ; CX = cursor x position
  152. ; DX = cursor y position
  153.     public    ReadMouse
  154. ReadMouse    proc    far
  155.     push    bp
  156.     mov    bp,sp
  157.     push    ds
  158.     push    si
  159.     push    bx
  160.     push    cx
  161.     push    dx
  162.  
  163.     mov    ax,3
  164.     int    33h
  165.  
  166.     lds    si,6[bp]
  167.     mov    [si],bx
  168.  
  169.     lds    si,10[bp]
  170.     mov    [si],cx
  171.  
  172.     lds    si,14[bp]
  173.     mov    [si],dx
  174.  
  175.  
  176.     pop    dx
  177.     pop    cx
  178.     pop    bx
  179.     pop    si
  180.     pop    ds
  181.  
  182.     pop    bp
  183.  
  184.     ret
  185. ReadMouse    endp
  186.  
  187. ; PlayRunSkipDump(sourcebuf, destbuf);
  188.     public PlayRunSkipDump
  189. PlayRunSkipDump    proc    far
  190.  
  191. ARGB        = 6
  192. PR_SRC_SEG    = ARGB+2
  193. PR_SRC_ADDR    = ARGB
  194. PR_DST_SEG    = ARGB+6
  195. PR_DST_ADDR    = ARGB+4
  196.  
  197.     push    bp
  198.     mov    bp,sp
  199.     push    si
  200.     push    di
  201.     push    es
  202.  
  203.     mov    si,PR_SRC_ADDR[bp]
  204.     mov    di,PR_DST_ADDR[bp]
  205.     mov    es,PR_DST_SEG[bp]
  206.  
  207.     push    ds            ; Save DS:DGROUP.
  208.     mov    ds,PR_SRC_SEG[bp]    ; SET DS:dstSeg.  NOT DGROUP.
  209.  
  210.     sub    ch,ch            ; SET CH = 0.
  211.     jmp    short nextOp
  212.  
  213. skip:
  214.     sub    cl,80h            ; Strip off sign bit, leaving skip cnt.
  215.     jz    longOp            ; cnt==0 indicates a long op.
  216. ; --- shortSkip ---
  217.     add    di,cx            ; skip # pixels.  (CH=0)
  218. ; --- variation on NEXTOP inline to minimize jmp's ---
  219. nextOp:                    ; Get and decode next op.
  220.     mov    cl,[si]
  221.     inc    si
  222.     jcxz    run
  223.     or    cl,cl            ; Test CL's sign bit.
  224.     jl    skip
  225. dump:
  226.     rep movsb            ; copy # pixels.  (CH=0)
  227. ; --- variation on NEXTOP inline to minimize jmp's ---
  228.     mov    cl,[si]
  229.     inc    si
  230.     or    cl,cl            ; Test CL's sign bit.
  231.     jl    skip
  232.     jg    dump
  233. run:
  234.     mov    cl,[si]            ; 8-bit unsigned count.
  235.     inc    si
  236.     lodsb                ; pixel value.
  237.     rep stosb            ; set # pixels to value.  (CH=0)
  238. ; --- variation on NEXTOP inline to minimize jmp's ---
  239.     mov    cl,[si]
  240.     inc    si
  241.     jcxz    run
  242.     or    cl,cl            ; Test CL's sign bit.
  243.     jl    skip
  244.     jmp    short dump
  245.  
  246. longOp:        ; NOTE: if load into CX, must clear CH afterwards.
  247.     lodsw                ; 16-bit unsigned count.
  248.     or    ax,ax            ; set flags.
  249.     jle    notLongSkip
  250. ;longSkip:
  251.     add    di,ax            ; skip # pixels.
  252.     jmp short nextOp
  253.         ; longSkip only used for > 2*127, so can't be very many,
  254.         ; so don't bother saving one jmp with inline NEXTOP.
  255.  
  256. notLongSkip:
  257.     jz    stop            ; long count of zero means "stop code".
  258.     mov    cx,ax            ; may SET CH non-zero.
  259.     sub    ch,80h            ; Clear sign bit.
  260.     cmp    ch,40h
  261.     jge    longRun
  262. ; --- For maximum speed on longDump, caller should insure src & dst are
  263. ; aligned.  To do so, caller must calculate whether
  264. ; src DATA will begin on same (odd or even) alignment as dst data.
  265. ; If not, first put a 1-byte Dump, which occupies 2 src bytes, thereby
  266. ; shifting relative alignment (src moves 2, dst moves 1).
  267. ;longDump
  268.     test    si,1            ; Insure src word-aligned.
  269.             ; In case caller didn't sync src & dst, we chose
  270.             ; to align src because we know it is of benefit --
  271.             ; aligning dst on 8-bit video cards might not be of
  272.             ; any benefit.
  273.     jz    dumpWordAligned
  274.     movsb                ; get to word boundary.
  275.     dec    cx
  276. dumpWordAligned:
  277.     shr    cx,1            ; Convert byte count to word count.
  278.     jc    dumpOddByte
  279.     rep movsw            ; Word-aligned.
  280. longOpDone:
  281.     sub    ch,ch            ; SET CH = 0.
  282.     jmp    short nextOp
  283.  
  284. dumpOddByte:
  285.     rep movsw            ; Word-aligned.
  286.     movsb
  287.     jmp    short longOpDone
  288.  
  289. longRun:
  290.     sub    ch,40h            ; Clear "longRun" bit.
  291.     lodsb
  292.     mov    ah,al            ; Replicate byte to word value.
  293.     test    di,1            ; Insure dst word-aligned.
  294.     jz    runWordAligned
  295.     stosb
  296.     dec    cx
  297. runWordAligned:
  298.     shr    cx,1            ; Convert byte count to word count.
  299.     jc    runOddByte
  300.     rep stosw            ; Word-aligned.
  301.     jmp    short longOpDone
  302.  
  303. runOddByte:
  304.     rep stosw            ; Word-aligned.
  305.     stosb
  306.     jmp    short longOpDone
  307.     
  308. stop:
  309.     pop    ds            ; Restore DS:DGROUP.
  310.  
  311.     mov    ax,di            ; RETURN final dstAddr.
  312.     pop    es
  313.     pop    di
  314.     pop    si
  315.     pop    bp
  316.     ret
  317.  
  318. PlayRunSkipDump    endp
  319.  
  320. ; clear the screen to a color
  321. ; cls(color);
  322.     public    cls
  323. cls    proc    far
  324.  
  325.     push    bp
  326.     mov    bp,sp
  327.  
  328.     push    di
  329.     push    es
  330.     push    cx
  331.  
  332.     mov    ax,0A000h
  333.     mov    es,ax
  334.     xor    di,di
  335.     
  336.     mov    al,6[bp]
  337.     mov    ah,al
  338.     mov    cx,32000
  339.     rep    stosw
  340.  
  341.     pop    cx
  342.     pop    es
  343.     pop    di
  344.  
  345.     pop    bp
  346.  
  347.     ret
  348.  
  349. cls    endp
  350.  
  351.     end
  352.